<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 9. Zend_Date</title>
<link rel="stylesheet" href="dbstyle.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.72.0">
<link rel="start" href="index.html" title="Programmer's Reference Guide">
<link rel="up" href="index.html" title="Programmer's Reference Guide">
<link rel="prev" href="zend.currency.migration.html" title="8.3. Migrating from Previous Versions">
<link rel="next" href="zend.date.definition.theory.html" title="9.2. Theory of Operation">
<link rel="chapter" href="introduction.html" title="Chapter 1. Introduction to Zend Framework">
<link rel="chapter" href="zend.acl.html" title="Chapter 2. Zend_Acl">
<link rel="chapter" href="zend.auth.html" title="Chapter 3. Zend_Auth">
<link rel="chapter" href="zend.cache.html" title="Chapter 4. Zend_Cache">
<link rel="chapter" href="zend.config.html" title="Chapter 5. Zend_Config">
<link rel="chapter" href="zend.console.getopt.html" title="Chapter 6. Zend_Console_Getopt">
<link rel="chapter" href="zend.controller.html" title="Chapter 7. Zend_Controller">
<link rel="chapter" href="zend.currency.html" title="Chapter 8. Zend_Currency">
<link rel="chapter" href="zend.date.html" title="Chapter 9. Zend_Date">
<link rel="chapter" href="zend.db.html" title="Chapter 10. Zend_Db">
<link rel="chapter" href="zend.debug.html" title="Chapter 11. Zend_Debug">
<link rel="chapter" href="zend.dojo.html" title="Chapter 12. Zend_Dojo">
<link rel="chapter" href="zend.dom.html" title="Chapter 13. Zend_Dom">
<link rel="chapter" href="zend.exception.html" title="Chapter 14. Zend_Exception">
<link rel="chapter" href="zend.feed.html" title="Chapter 15. Zend_Feed">
<link rel="chapter" href="zend.filter.html" title="Chapter 16. Zend_Filter">
<link rel="chapter" href="zend.form.html" title="Chapter 17. Zend_Form">
<link rel="chapter" href="zend.gdata.html" title="Chapter 18. Zend_Gdata">
<link rel="chapter" href="zend.http.html" title="Chapter 19. Zend_Http">
<link rel="chapter" href="zend.infocard.html" title="Chapter 20. Zend_InfoCard">
<link rel="chapter" href="zend.json.html" title="Chapter 21. Zend_Json">
<link rel="chapter" href="zend.layout.html" title="Chapter 22. Zend_Layout">
<link rel="chapter" href="zend.ldap.html" title="Chapter 23. Zend_Ldap">
<link rel="chapter" href="zend.loader.html" title="Chapter 24. Zend_Loader">
<link rel="chapter" href="zend.locale.html" title="Chapter 25. Zend_Locale">
<link rel="chapter" href="zend.log.html" title="Chapter 26. Zend_Log">
<link rel="chapter" href="zend.mail.html" title="Chapter 27. Zend_Mail">
<link rel="chapter" href="zend.measure.html" title="Chapter 28. Zend_Measure">
<link rel="chapter" href="zend.memory.html" title="Chapter 29. Zend_Memory">
<link rel="chapter" href="zend.mime.html" title="Chapter 30. Zend_Mime">
<link rel="chapter" href="zend.openid.html" title="Chapter 31. Zend_OpenId">
<link rel="chapter" href="zend.paginator.html" title="Chapter 32. Zend_Paginator">
<link rel="chapter" href="zend.pdf.html" title="Chapter 33. Zend_Pdf">
<link rel="chapter" href="zend.registry.html" title="Chapter 34. Zend_Registry">
<link rel="chapter" href="zend.rest.html" title="Chapter 35. Zend_Rest">
<link rel="chapter" href="zend.search.lucene.html" title="Chapter 36. Zend_Search_Lucene">
<link rel="chapter" href="zend.server.html" title="Chapter 37. Zend_Server">
<link rel="chapter" href="zend.service.html" title="Chapter 38. Zend_Service">
<link rel="chapter" href="zend.session.html" title="Chapter 39. Zend_Session">
<link rel="chapter" href="zend.soap.html" title="Chapter 40. Zend_Soap">
<link rel="chapter" href="zend.test.html" title="Chapter 41. Zend_Test">
<link rel="chapter" href="zend.text.html" title="Chapter 42. Zend_Text">
<link rel="chapter" href="zend.timesync.html" title="Chapter 43. Zend_TimeSync">
<link rel="chapter" href="zend.translate.html" title="Chapter 44. Zend_Translate">
<link rel="chapter" href="zend.uri.html" title="Chapter 45. Zend_Uri">
<link rel="chapter" href="zend.validate.html" title="Chapter 46. Zend_Validate">
<link rel="chapter" href="zend.version.html" title="Chapter 47. Zend_Version">
<link rel="chapter" href="zend.view.html" title="Chapter 48. Zend_View">
<link rel="chapter" href="zend.xmlrpc.html" title="Chapter 49. Zend_XmlRpc">
<link rel="appendix" href="requirements.html" title="Appendix A. Zend Framework Requirements">
<link rel="appendix" href="coding-standard.html" title="Appendix B. Zend Framework Coding Standard for PHP">
<link rel="appendix" href="copyrights.html" title="Appendix C. Copyright Information">
<link rel="index" href="the.index.html" title="Index">
<link rel="section" href="zend.date.html#zend.date.introduction" title="9.1. Introduction">
<link rel="section" href="zend.date.definition.theory.html" title="9.2. Theory of Operation">
<link rel="section" href="zend.date.basic.html" title="9.3. Basic Methods">
<link rel="section" href="zend.date.overview.html" title="9.4. Zend_Date API Overview">
<link rel="section" href="zend.date.creation.html" title="9.5. Creation of dates">
<link rel="section" href="zend.date.constants.html" title="9.6. Constants for General Date Functions">
<link rel="section" href="zend.date.additional.html" title="9.7. Working examples">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navheader"><table width="100%" summary="Navigation header">
<tr><th colspan="3" align="center">Chapter 9. Zend_Date</th></tr>
<tr>
<td width="20%" align="left">
<a accesskey="p" href="zend.currency.migration.html">Prev</a> </td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="zend.date.definition.theory.html">Next</a>
</td>
</tr>
</table></div>
<div class="chapter" lang="en">
<div class="titlepage"><div><div><h2 class="title">
<a name="zend.date"></a>Chapter 9. Zend_Date</h2></div></div></div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="sect1"><a href="zend.date.html#zend.date.introduction">9.1. Introduction</a></span></dt>
<dd><dl>
<dt><span class="sect2"><a href="zend.date.html#zend.date.setdefaulttimezone">9.1.1. Always Set a Default Timezone</a></span></dt>
<dt><span class="sect2"><a href="zend.date.html#zend.date.why">9.1.2. Why Use Zend_Date?</a></span></dt>
</dl></dd>
<dt><span class="sect1"><a href="zend.date.definition.theory.html">9.2. Theory of Operation</a></span></dt>
<dd><dl><dt><span class="sect2"><a href="zend.date.definition.theory.html#zend.date.theory.internals">9.2.1. Internals</a></span></dt></dl></dd>
<dt><span class="sect1"><a href="zend.date.basic.html">9.3. Basic Methods</a></span></dt>
<dd><dl>
<dt><span class="sect2"><a href="zend.date.basic.html#zend.date.basic.creation">9.3.1. The current date</a></span></dt>
<dt><span class="sect2"><a href="zend.date.basic.html#zend.date.basic.functions">9.3.2. Zend_Date by Example</a></span></dt>
<dd><dl>
<dt><span class="sect3"><a href="zend.date.basic.html#zend.date.simple.functions.get">9.3.2.1. Output a Date</a></span></dt>
<dt><span class="sect3"><a href="zend.date.basic.html#zend.date.simple.functions.set">9.3.2.2. Setting a Date</a></span></dt>
<dt><span class="sect3"><a href="zend.date.basic.html#zend.date.simple.functions.add">9.3.2.3. Adding and Subtracting Dates</a></span></dt>
<dt><span class="sect3"><a href="zend.date.basic.html#zend.date.simple.functions.compare">9.3.2.4. Comparison of dates</a></span></dt>
</dl></dd>
</dl></dd>
<dt><span class="sect1"><a href="zend.date.overview.html">9.4. Zend_Date API Overview</a></span></dt>
<dd><dl>
<dt><span class="sect2"><a href="zend.date.overview.html#zend.date.options">9.4.1. Zend_Date Options</a></span></dt>
<dd><dl>
<dt><span class="sect3"><a href="zend.date.overview.html#zend.date.options.formattype">9.4.1.1. Selecting the date format type</a></span></dt>
<dt><span class="sect3"><a href="zend.date.overview.html#zend.date.options.fixdst">9.4.1.2. DST and Date Math</a></span></dt>
<dt><span class="sect3"><a href="zend.date.overview.html#zend.date.options.extendmonth">9.4.1.3. Month Calculations</a></span></dt>
<dt><span class="sect3"><a href="zend.date.overview.html#zend.date.options.cache">9.4.1.4. Speed up date localization and normalization with Zend_Cache</a></span></dt>
<dt><span class="sect3"><a href="zend.date.overview.html#zend.date.options.timesync">9.4.1.5. Receiving syncronised timestamps with Zend_TimeSync</a></span></dt>
</dl></dd>
<dt><span class="sect2"><a href="zend.date.overview.html#zend.date.values">9.4.2. Working with Date Values</a></span></dt>
<dt><span class="sect2"><a href="zend.date.overview.html#id.date.basic">9.4.3. Basic <code class="code">Zend_Date</code> Operations Common to Many Date Parts</a></span></dt>
<dd><dl>
<dt><span class="sect3"><a href="zend.date.overview.html#id.date.basic.parts">9.4.3.1. List of Date Parts</a></span></dt>
<dt><span class="sect3"><a href="zend.date.overview.html#id.date.basic.operations">9.4.3.2. List of Date Operations</a></span></dt>
</dl></dd>
<dt><span class="sect2"><a href="zend.date.overview.html#zend.date.others.comparison">9.4.4. Comparing Dates</a></span></dt>
<dt><span class="sect2"><a href="zend.date.overview.html#zend.date.others.gettingparts">9.4.5. Getting Dates and Date Parts</a></span></dt>
<dt><span class="sect2"><a href="zend.date.overview.html#zend.date.others.fractions">9.4.6. Working with Fractions of Seconds</a></span></dt>
<dt><span class="sect2"><a href="zend.date.overview.html#zend.date.other.sun">9.4.7. Sunrise / Sunset</a></span></dt>
</dl></dd>
<dt><span class="sect1"><a href="zend.date.creation.html">9.5. Creation of dates</a></span></dt>
<dd><dl>
<dt><span class="sect2"><a href="zend.date.creation.html#zend.date.creation.actual">9.5.1. Create the actual date</a></span></dt>
<dt><span class="sect2"><a href="zend.date.creation.html#zend.date.creation.database">9.5.2. Create a date from database</a></span></dt>
<dt><span class="sect2"><a href="zend.date.creation.html#zend.date.creation.array">9.5.3. Create dates from an array</a></span></dt>
</dl></dd>
<dt><span class="sect1"><a href="zend.date.constants.html">9.6. Constants for General Date Functions</a></span></dt>
<dd><dl>
<dt><span class="sect2"><a href="zend.date.constants.html#zend.date.constants.using">9.6.1. Using Constants</a></span></dt>
<dt><span class="sect2"><a href="zend.date.constants.html#zend.date.constants.list">9.6.2. List of All Constants</a></span></dt>
<dt><span class="sect2"><a href="zend.date.constants.html#zend.date.constants.selfdefinedformats">9.6.3. Self-Defined OUTPUT Formats with ISO</a></span></dt>
<dt><span class="sect2"><a href="zend.date.constants.html#zend.date.constants.phpformats">9.6.4. Self-defined OUTPUT formats using PHP's date() format specifiers</a></span></dt>
</dl></dd>
<dt><span class="sect1"><a href="zend.date.additional.html">9.7. Working examples</a></span></dt>
<dd><dl>
<dt><span class="sect2"><a href="zend.date.additional.html#zend.date.additional.checking">9.7.1. Checking dates</a></span></dt>
<dt><span class="sect2"><a href="zend.date.additional.html#zend.date.additional.sunrise-sunset">9.7.2. Sunrise and Sunset</a></span></dt>
<dt><span class="sect2"><a href="zend.date.additional.html#zend.date.additional.timezones">9.7.3. Timezones</a></span></dt>
</dl></dd>
</dl>
</div>
<div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="zend.date.introduction"></a>9.1. Introduction</h2></div></div></div>
<p>
        The <code class="code">Zend_Date</code> component offers a detailed, but simple API for manipulating dates and times. Its
        methods accept a wide variety of types of information, including date parts, in numerous combinations yielding
        many features and possibilities above and beyond the existing PHP date related functions. For the very latest
        manual updates, please see
        <a href="http://framework.zend.com/wiki/display/ZFDOCDEV/Home" target="_top">our online manual
        (frequently synced to Subversion)</a>
        .
    </p>
<p>
        Although simplicity remains the goal, working with localized dates and times while modifying, combining, and
        comparing parts involves some unavoidable complexity. Dates, as well as times, are often written differently in
        different locales. For example, some place the month first, while other write the year first when expressing
        calendar dates. For more information about handling localization and normalization, please refer to
        <a href="zend.locale.date.datesandtimes.html" title="25.4. Working with Dates and Times"><code class="code">Zend_Locale</code>
        </a>
        .
    </p>
<p>
        <code class="code">Zend_Date</code> also supports abbreviated names of months in many languages. <code class="code">Zend_Locale</code>
        facilitates the normalization of localized month and weekday names to timestamps, which may, in turn, be shown
        localized to other regions.
    </p>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.date.setdefaulttimezone"></a>9.1.1. Always Set a Default Timezone</h3></div></div></div>
<p>
            Before using any date related functions in PHP or the Zend Framework, first make certain your application
            has a correct default timezone, by either setting the TZ environment variable, using the
            <code class="code">date.timezone</code> php.ini setting, or using
            <a href="http://php.net/date_default_timezone_set" target="_top">date_default_timezone_set()</a>
            . In PHP, we can adjust all date and time related functions to work for a particular user by setting a
            default timezone according to the user's expectations. For a complete list of timezone settings, see the
            <a href="http://unicode.org/cldr/data/diff/supplemental/territory_containment_un_m_49.html" target="_top">CLDR Timezone Identifier List</a>
            .
            </p>
<div class="example">
<a name="zend.date.setdefaulttimezone.example-1"></a><p class="title"><b>Example 9.1. Setting a default timezone</b></p>
<div class="example-contents"><pre class="programlisting">&lt;?php
date_default_timezone_set('America/Los_Angeles'); // timezone for an American in California
date_default_timezone_set('Europe/Berlin');       // timezone for a German in Germany
                </pre></div>
</div>
<p><br class="example-break">
            <span class="strong"><strong>When creating Zend_Date instances, their timezone will automatically become the
            current default timezone!</strong></span> Thus, the timezone setting will account for any Daylight Savings Time
            (DST) in effect, eliminating the need to explicitly specify DST.
        </p>
<p>
            Keep in mind that the timezones <span class="strong"><strong>UTC</strong></span> and
            <span class="strong"><strong>GMT</strong></span> do not include Daylight Saving Time. This means that even
            if you define per hand that <code class="code">Zend_Date</code> should work with DST, it would automatically
            be switched back for the instances of <code class="code">Zend_Date</code> which have been set to UTC or GMT.
        </p>
</div>
<div class="sect2" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="zend.date.why"></a>9.1.2. Why Use Zend_Date?</h3></div></div></div>
<p>
            <code class="code">Zend_Date</code> offers the following features, which extend the scope of PHP date functions:
        </p>
<div class="itemizedlist"><ul type="opencircle">
<li style="list-style-type: circle">
<p>
                    Simple API
                </p>
<p>
                    <code class="code">Zend_Date</code> offers a very simple API, which combines the best of date/time functionality
                    from four programming languages. It is possible, for example, to add or compare two times within a
                    single row.
                </p>
</li>
<li style="list-style-type: circle">
<p>
                    Completely internationalized
                </p>
<p>
                    All full and abbreviated names of months and weekdays are supported for more than 130 languages.
                    Methods support both input and the output of dates using the localized names of months and weekdays,
                    in the conventional format associated with each locale.
                </p>
</li>
<li style="list-style-type: circle">
<p>
                    Unlimited timestamps
                </p>
<p>
                    Although PHP 5.2 docs state, "The valid range of a timestamp is typically from Fri, 13 Dec 1901
                    20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT," <code class="code">Zend_Date</code> supports a nearly unlimited
                    range, with the help of the BCMath extension. If BCMath is not available, then Zend_Date will have
                    reduced support only for timestamps within the range of the <code class="code">float</code> type supported by
                    your server. "The size of a float is platform-dependent, although a maximum of ~1.8e308 with a
                    precision of roughly 14 decimal digits is a common value (that's 64 bit IEEE format)." [
                    <a href="http://www.php.net/float" target="_top">http://www.php.net/float</a>
                    ].  Additionally, inherent limitations of float data types, and rounding error of float numbers
                    may introduce errors into calculations.  To avoid these problems, the ZF I18n components use
                    BCMath extension, if available.
                </p>
</li>
<li style="list-style-type: circle">
<p>
                    Support for ISO_8601 date specifications
                </p>
<p>
                    ISO_8601 date specifications are supported. Even partially compliant ISO_8601 date specifications
                    will be identified. These date formats are particularly useful when working with databases. For
                    example, even though MsSQL and
                    <a href="http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html" target="_top">MySQL</a>
                    differ a little from each other, both are supported by <code class="code">Zend_Date</code> using the
                    <a href="zend.date.constants.html#zend.date.constants.list" title="9.6.2. List of All Constants">Zend_Date::ISO_8601</a>
                    format specification constant. When date strings conform to "Y/m/d" or "Y-m-d H:i:s", according to
                    PHP date() format tokens, use Zend_Date's built-in support for ISO 8601 formatted dates.
                </p>
</li>
<li style="list-style-type: circle">
<p>
                    Calculate sunrise and sunset
                </p>
<p>
                    For any place and day, the times for sunrise and sunset can be displayed, so that you won't miss a
                    single daylight second for working on your favorite PHP project :)
                </p>
</li>
</ul></div>
</div>
</div>
</div>
<div class="navfooter"><table width="100%" summary="Navigation footer">
<tr>
<td width="40%" align="left">
<a accesskey="p" href="zend.currency.migration.html">Prev</a> </td>
<td width="20%" align="center"> </td>
<td width="40%" align="right"> <a accesskey="n" href="zend.date.definition.theory.html">Next</a>
</td>
</tr>
<tr>
<td width="40%" align="left" valign="top">8.3. Migrating from Previous Versions </td>
<td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td>
<td width="40%" align="right" valign="top"> 9.2. Theory of Operation</td>
</tr>
</table></div>
<div class="revinfo"></div>
</body>
</html>
